package fourteen;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("./a/fos.txt");
        FileInputStream fis = new FileInputStream(file);
        byte[] data = new byte[(int) file.length()];//创建与文件等长的字节数组
        fis.read(data);//一次性读取数据到data中
//        for (byte b :
//                data) {
//            System.out.println(b);
//        }
        for (Byte b: data) {
            System.out.println(b);
        }

        String line = new String(data, StandardCharsets.UTF_8); //将data中的字节还原为字符串
//        String line = new String(data); //将data中的字节还原为字符串
//        line.getBytes(StandardCharsets.UTF_8);
        System.out.println(line);
        fis.close();
    }
}
